﻿CREATE PROCEDURE [acms].[Post_GetAllByTopicGroupIdAndParentPath]
	@TopicGroupId int,
	@ParentPath varchar(255),
	@SiteVersion datetime
AS
	declare @tmp DateTime
	
	set @tmp = acms.GetPublishDate(@SiteVersion)

	if(@tmp is null and @SiteVersion is not null)
		return

	if not Right(@ParentPath, 1) = '/'
		set @ParentPath = @ParentPath + '/'

	SELECT distinct a.*, b.ParentPath, b.PublishDate as SiteVersion
	FROM [Post_View] a
		inner join [PostPositions] b on a.Id = b.PostId and isnull(b.PublishDate, '9999/12/31') = isnull(@tmp, '9999/12/31')
		inner join [PostTopics] c on a.Id = c.PostId and c.Deleted = 0
		inner join [Topics] d on c.TopicId = d.Id
	Where d.TopicGroupId = @TopicGroupId
		and b.ParentPath = @ParentPath
	ORDER By Sequence

RETURN 0;